package com.alquiler.services;

import java.sql.Time;
import java.util.List;

import com.alquiler.dao.TarifaDao;
import com.alquiler.entities.Tarifa;
import com.alquiler.managers.SimpleEntityManager;
import com.alquiler.types.CATEGORIA;

public class TarifaService {
	
	private TarifaDao tarifaDao;	
	
	public TarifaService() {		
		this.tarifaDao = new TarifaDao(SimpleEntityManager.getInstance().getEntityManager());		
	}
	
	
	public List<Tarifa> findAll(){
        return tarifaDao.findAll();
	}
	
	public Tarifa findById(Integer idTarifa){
        return tarifaDao.findById(idTarifa);
	}
	
	
	public Tarifa getTarifaByCategoriaAndHora(Time hora, CATEGORIA categoria ){
        return tarifaDao.getTarifaByCategoriaAndHora(hora, categoria);
	}
	
	
	
	public void saveTarifa(Tarifa tarifa){		
	
		
		try{
            SimpleEntityManager.getInstance().beginTransaction();	          
            tarifaDao.save(tarifa);
            SimpleEntityManager.getInstance().commit();
        }catch(Exception e){
            e.printStackTrace();
            SimpleEntityManager.getInstance().rollBack();
        }		
	}
	
	public void updateTarifa(Tarifa tarifa){
		
		try{
			SimpleEntityManager.getInstance().beginTransaction();
			tarifaDao.update(tarifa);				
		    SimpleEntityManager.getInstance().commit();
        }catch(Exception e){
            e.printStackTrace();
            SimpleEntityManager.getInstance().rollBack();
        }
		
	}
	
	
	public void deleteTarifa(Tarifa tarifa) throws Exception{
		try{
				
			SimpleEntityManager.getInstance().beginTransaction();
			tarifaDao.remove(tarifa);	
			SimpleEntityManager.getInstance().commit();
		  
        }catch(Exception e){        	
            SimpleEntityManager.getInstance().rollBack();       
        }
		
	}

}
